<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>微信</title>
    <style>
        html,
        body,
        img,
        div,
        input,
        button,
        p,
        ul,
        li {
            margin: 0;
            padding: 0;
            border: 0;
        }
        
        .clearfix::after {
            display: block;
            height: 0;
            content: "";
            visibility: hidden;
            clear: both;
        }
        
        #iphone {
            position: absolute;
            top: 50%;
            left: 50%;
            border: 2px solid #000000;
            border-radius: 30px;
            width: 280px;
            height: 560px;
            -webkit-transform: translate(-50%, -50%);
            -moz-transform: translate(-50%, -50%);
            transform: translate(-50%, -50%);
        }
        
        #contant {
            position: absolute;
            top: 50%;
            left: 50%;
            border: 2px solid #000000;
            width: 240px;
            height: 400px;
            -webkit-transform: translate(-50%, -50%);
            -moz-transform: translate(-50%, -50%);
            transform: translate(-50%, -50%);
        }
        
        #displayWrapper {
            padding: 10px;
            height: 339px;
            overflow: auto;
        }
        
        #inputWrapper {
            position: absolute;
            bottom: 0;
            border-top: 1px solid #A5A3A3;
            padding: 5px 0;
            width: 100%;
            background-color: #F1EDED;
        }
        
        #headSculpture {
            float: left;
            margin-left: 5px;
            border-radius: 5px;
            width: 30px;
            height: 30px;
            cursor: pointer;
        }
        
        #inputZone {
            float: left;
            margin-left: 10px;
            border-radius: 5px;
            padding: 0 10px;
            height: 30px;
            width: 120px;
            font-size: 16px;
            line-height: 18px;
            outline: none;
        }
        
        #sendMsg {
            float: left;
            margin-left: 10px;
            border-radius: 5px;
            width: 40px;
            height: 30px;
            background-color: #5AE47A;
            font-size: 14px;
            line-height: 30px;
            color: #ffffff;
            outline: none;
            cursor: pointer;
        }
        
        .left img {
            float: left;
            margin-right: 10px;
            border-radius: 5px;
            width: 30px;
            height: 30px;
        }
        
        .left p {
            float: left;
            border-radius: 5px;
            padding: 5px;
            max-width: 120px;
            background-color: #1FE93D;
            font-size: 14px;
            line-height: 16px;
            color: #ffffff;
        }
        
        .right img {
            float: right;
            margin-left: 10px;
            border-radius: 5px;
            width: 30px;
            height: 30px;
        }
        
        .right p {
            float: right;
            border-radius: 5px;
            padding: 5px;
            max-width: 150px;
            background-color: #1FE93D;
            font-size: 14px;
            line-height: 16px;
            color: #ffffff;
        }
        
        li {
            margin: 5px 0;
            list-style-type: none;
        }
    </style>
</head>

<body>
    <div id="iphone">
        <div id="contant">
            <div id="displayWrapper">
                <div id="displayZone">
                    <ul id="displayList">
                    </ul>
                </div>
            </div>
            <div id="inputWrapper" class="clearfix">
                <img id="headSculpture" src="./img/haha.jpg" alt="headSculpture">
                <input id="inputZone" type="text">
                <button id="sendMsg">发送</button>
            </div>
        </div>
    </div>
    <script>
        var headSculpture = document.getElementById('headSculpture');
        var sendMsg = document.getElementById("sendMsg");
        var inputZone = document.getElementById("inputZone");
        var displayList = document.getElementById("displayList");
        var img = ['./img/haha.jpg', './img/miaomiao.jpg'];
        var i = 0;
        headSculpture.onclick = function() {
            i++;
            i = i % 2;
            this.src = img[i];
        }
        sendMsg.onclick = send;
        inputZone.onkeydown = function(event) {
            if (event.keyCode === 13) {
                send();
            }
        }

        function send() {
            if (inputZone.value.trim() !== '') {
                if (i % 2 == 0) {
                    displayList.innerHTML = '<li class="left clearfix"><img src="' + img[i] + '"alt="headSculpture"><p>' + inputZone.value + '</p></li>' + displayList.innerHTML;
                } else {
                    displayList.innerHTML = '<li class="right clearfix"><img src="' + img[i] + '"alt="headSculpture"><p>' + inputZone.value + '</p></li>' + displayList.innerHTML;
                }
                inputZone.value = '';
            }
        }
    </script>
</body>

</html>